package com.cans.support;

import com.cans.dto.ResDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author cans
 * @date 2018/6/4
 * @description 全局异常处理
 */
@ControllerAdvice
public class GlobalDefaultExceptionHandler {

    private Logger logger = LoggerFactory.getLogger(getClass());

    private final String SERVER = "[服务器]";

    /**
     * 声明要捕获的异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResDto runtimeExceptionHandler(Exception e) {
        logger.error("全局异常处理",e);
        return ResDto.fait(SERVER + "异常:" + e.getMessage());
    }
}
